package com.tonghe.controller;

import com.tonghe.domain.ResponseResult;
import com.tonghe.service.UploadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @Date:2022/9/8- 09- 08- 15:14
 * @Author: tonghe
 **/
@RestController
public class UploadController {

    @Autowired
    private UploadService uploadService;

    /** 上传文件 */
    @PostMapping("/upload")
    public ResponseResult uploadImg(@RequestParam("img") MultipartFile multipartFile) {
        try {
            return uploadService.uploadImg(multipartFile);
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException("文件上传上传失败");
        }
    }

}
